home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte19 / end.c < prev    next >
C/C++ Source or Header  |  1996-04-29  |  7KB  |  227 lines

  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include "End.h"
  5. #include <vfw.h>
  6.  
  7.  
  8. #if defined (WIN32)
  9.     #define IS_WIN32 TRUE
  10. #else
  11.     #define IS_WIN32 FALSE
  12. #endif
  13.  
  14. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  15. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  16. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  17.  
  18.  
  19. HINSTANCE hInst;   // current instance
  20.  
  21. LPCTSTR lpszAppName = "MyApp";
  22. LPCTSTR lpszTitle   = "My Application"; 
  23.  
  24. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  25.  
  26.  
  27. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  28.                       LPTSTR lpCmdLine, int nCmdShow)
  29. {
  30.    MSG      msg;
  31.    HWND     hWnd; 
  32.    WNDCLASS wc;
  33.  
  34.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  35.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  36.    wc.cbClsExtra    = 0;                      
  37.    wc.cbWndExtra    = 0;                      
  38.    wc.hInstance     = hInstance;              
  39.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  40.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  41.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  42.    wc.lpszMenuName  = lpszAppName;              
  43.    wc.lpszClassName = lpszAppName;              
  44.  
  45.    if ( IS_WIN95 )
  46.    {
  47.       if ( !RegisterWin95( &wc ) )
  48.          return( FALSE );
  49.    }
  50.    else if ( !RegisterClass( &wc ) )
  51.       return( FALSE );
  52.  
  53.    hInst = hInstance; 
  54.  
  55.    hWnd = CreateWindow( lpszAppName, 
  56.                         lpszTitle,    
  57.                         WS_OVERLAPPEDWINDOW, 
  58.                         CW_USEDEFAULT, 0, 
  59.                         CW_USEDEFAULT, 0,  
  60.                         NULL,              
  61.                         NULL,              
  62.                         hInstance,         
  63.                         NULL               
  64.                       );
  65.  
  66.    if ( !hWnd ) 
  67.       return( FALSE );
  68.  
  69.    ShowWindow( hWnd, nCmdShow ); 
  70.    UpdateWindow( hWnd );         
  71.  
  72.    while( GetMessage( &msg, NULL, 0, 0) )   
  73.    {
  74.       TranslateMessage( &msg ); 
  75.       DispatchMessage( &msg );  
  76.    }
  77.  
  78.    return( msg.wParam ); 
  79. }
  80.  
  81.  
  82. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  83. {
  84.     WNDCLASSEX wcex;
  85.  
  86.    wcex.style         = lpwc->style;
  87.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  88.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  89.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  90.    wcex.hInstance     = lpwc->hInstance;
  91.    wcex.hIcon         = lpwc->hIcon;
  92.    wcex.hCursor       = lpwc->hCursor;
  93.    wcex.hbrBackground = lpwc->hbrBackground;
  94.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  95.    wcex.lpszClassName = lpwc->lpszClassName;
  96.  
  97.    // Added elements for Windows 95.
  98.    //...............................
  99.    wcex.cbSize = sizeof(WNDCLASSEX);
  100.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  101.                             IMAGE_ICON, 16, 16,
  102.                             LR_DEFAULTCOLOR );
  103.             
  104.    return RegisterClassEx( &wcex );
  105. }
  106.  
  107. HWND hMCIWnd = NULL;   // MCIWnd window handle
  108.  
  109. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  110. {
  111.    switch( uMsg )
  112.    {
  113.       case WM_CREATE :
  114.               // create MCIWnd window
  115.               //.....................
  116.  
  117.               hMCIWnd = MCIWndCreate(hWnd, hInst, 
  118.                                      WS_VISIBLE | 
  119.                                      WS_CHILD | 
  120.                                      WS_OVERLAPPED |
  121.                                      WS_CAPTION |
  122.                                      WS_BORDER |
  123.                                      MCIWNDF_NOTIFYMODE |
  124.                                      MCIWNDF_SHOWALL | 
  125.                                      MCIWNDF_NOPLAYBAR, 
  126.                                      NULL
  127.                                     );
  128.               break;
  129.  
  130.       case WM_COMMAND :
  131.               switch( LOWORD( wParam ) )
  132.               {
  133.                  // file commands
  134.                  //..............
  135.  
  136.                  case IDM_OPEN_DIALOG :
  137.                          if ( MCIWndOpenDialog(hMCIWnd) )
  138.                              MCIWndValidateMedia(hMCIWnd);
  139.                          break;
  140.                          
  141.                  case IDM_CLOSE :
  142.                          MCIWndClose(hMCIWnd);
  143.                          break;
  144.  
  145.                  // playback
  146.                  //.........
  147.                                            
  148.                  case IDM_PLAY :
  149.                          MCIWndPlay(hMCIWnd);
  150.                          break;
  151.  
  152.                  case IDM_PLAY_REVERSE :
  153.                          MCIWndPlayReverse(hMCIWnd);
  154.                          break;
  155.                                    
  156.                  case IDM_STOP :
  157.                          MCIWndStop(hMCIWnd);
  158.                          break;
  159.  
  160.                  // Set position
  161.                  //.............
  162.                                            
  163.                  case IDM_HOME :
  164.                          MCIWndHome(hMCIWnd);
  165.                          break;
  166.                  
  167.                  case IDM_END :
  168.                          MCIWndEnd(hMCIWnd);
  169.                          break;
  170.                                            
  171.                  // other commands
  172.                  //...............
  173.  
  174.                  case IDM_ABOUT :
  175.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  176.                         break;
  177.  
  178.                  case IDM_EXIT :
  179.                         DestroyWindow(hWnd);
  180.                         break;
  181.               }
  182.               break;
  183.  
  184.       case WM_DESTROY :
  185.               // destroy MCIWnd, if one exists
  186.               //..............................
  187.  
  188.               if (hMCIWnd)
  189.                   MCIWndDestroy(hMCIWnd);
  190.  
  191.               PostQuitMessage(0);
  192.               break;
  193.  
  194.       default :
  195.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  196.    }
  197.  
  198.    return( 0L );               
  199. }
  200.  
  201.  
  202. LRESULT CALLBACK About( HWND hDlg,           
  203.                         UINT message,        
  204.                         WPARAM wParam,       
  205.                         LPARAM lParam)
  206. {
  207.    switch (message) 
  208.    {
  209.        case WM_INITDIALOG: 
  210.                return (TRUE);
  211.  
  212.        case WM_COMMAND:                              
  213.                if (   LOWORD(wParam) == IDOK         
  214.                    || LOWORD(wParam) == IDCANCEL)    
  215.                {
  216.                        EndDialog(hDlg, TRUE);        
  217.                        return (TRUE);
  218.                }
  219.                break;
  220.    }
  221.  
  222.    return (FALSE); 
  223. }
  224.  
  225.  
  226.  
  227.